﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PPI.Client.Utils
{
    public class RegisterError
    {
        public RegisterError()
        {

        }

        public static void SaveError(Exception ex)
        {
            try
            {
                string errorFileName = PPI.Constants.K_ERRORPATH;
                FileInfo errorFile = new FileInfo(errorFileName);
                if (!errorFile.Exists)
                    errorFile.Create();


                StringBuilder errorBuilder = new StringBuilder();
                errorBuilder.AppendLine(string.Format("Error Log at {0} {1}:", System.DateTime.Now.ToShortDateString(), System.DateTime.Now.ToShortTimeString()));
                errorBuilder.AppendLine(string.Format("Exception Name: {0}", ex.GetType()));
                errorBuilder.AppendLine(string.Format("Class: {0}", ex.Source));
                errorBuilder.AppendLine(string.Format("Message: {0}", ex.Message));
                errorBuilder.AppendLine(string.Format("Stack Trace: {0}", ex.StackTrace));

                StreamWriter writer = File.AppendText(errorFileName);
                writer.WriteLine(errorBuilder.ToString());
                writer.Close();
            }
            catch {
            
            }
        }
    }
}
